new Vue({
    el : "#login",
    data : function () {
        return {
            show_manager : true,
            show_user : false,
            account : "",
            password : "",
        }
    },
    methods : {
        /*切换登录*/
        cutover : function () {
            if (this.show_manager){
                this.show_manager = false
                this.show_user = true
                this.account = ""
                this.password = ""
            } else {
                this.show_user = false
                this.show_manager = true
                this.account = ""
                this.password = ""
            }
        },
        /*登录*/
        login : function () {
            if (this.show_manager){
                // 管理员登录
                $.post("/login", {
                    username: this.account,
                    password : this.password
                }, function (data) {
                    const json = $.parseJSON(data)
                    if (json.code === 0){
                        // 登录成功
                        let timestamp = new Date()
                        window.location.href = "/manage/manager.html?t=" + timestamp.valueOf()
                    } else {
                        layer.alert(json.msg, {
                            icon: 2,
                            skin: 'layer-ext-moon'
                        })
                    }
                })
            } else {
                // 用户登录
                $.post("/login", {
                    username: this.account,
                    password : this.password
                }, function (data) {
                    const json = $.parseJSON(data)
                    if (json.code === 0){
                        // 登录成功
                        let timestamp = new Date()
                        window.location.href = "/user/home.html?t=" + timestamp.valueOf()
                    } else {
                        layer.alert(json.msg, {
                            icon: 2,
                            skin: 'layer-ext-moon'
                        })
                    }
                })
            }
        },
    }
})